/**
 * Copyright &copy; 2016-2017 <a href="https://www.lczyfz.com">联创智云</a> All rights reserved.
 */
package com.lczyfz.campusinfo.modules.campusinfohelp.service;

import java.util.Date;
import java.util.List;

import com.lczyfz.campusinfo.common.utils.IdGen;
import com.lczyfz.campusinfo.common.utils.StringUtils;
import com.lczyfz.campusinfo.modules.campusinfohelp.entity.CampusinfoProDetail;
import com.lczyfz.campusinfo.modules.cms.dao.ArticleDataDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lczyfz.campusinfo.common.persistence.Page;
import com.lczyfz.campusinfo.common.service.CrudService;
import com.lczyfz.campusinfo.modules.campusinfohelp.entity.CampusinfoProblem;
import com.lczyfz.campusinfo.modules.campusinfohelp.dao.CampusinfoProblemDao;
import com.lczyfz.campusinfo.modules.campusinfohelp.dao.CampusinfoProDetailDao;
/**
 * 问题列表Service
 * @author zms
 * @version 2018-04-16
 */
@Service
@Transactional(readOnly = true)
public class CampusinfoProblemService extends CrudService<CampusinfoProblemDao, CampusinfoProblem> {
	@Autowired
	private CampusinfoProDetailDao campusinfoProDetailDao;
	public CampusinfoProblem get(String id) {
		return super.get(id);
	}
	
	public List<CampusinfoProblem> findList(CampusinfoProblem campusinfoProblem) {
		return super.findList(campusinfoProblem);
	}
	
	public Page<CampusinfoProblem> findPage(Page<CampusinfoProblem> page, CampusinfoProblem campusinfoProblem) {
		return super.findPage(page, campusinfoProblem);
	}
	
	@Transactional(readOnly = false)
	public void save(CampusinfoProblem campusinfoProblem) {
		CampusinfoProDetail campusinfoProDetail = new CampusinfoProDetail();

		if (StringUtils.isBlank(campusinfoProblem.getId())){
			campusinfoProblem.preInsert();
//			campusinfoProblem.setCreateDate(new Date());
//			campusinfoProblem.setId(IdGen.uuid());
//			campusinfoProblem.setCreateDate(new Date());
//			campusinfoProblem.setUpdateDate(new Date());
			campusinfoProDetail.preInsert();
			campusinfoProDetail.setProId(campusinfoProblem.getId());
			campusinfoProDetail.setProContent(campusinfoProblem.getContent());
			campusinfoProDetail.setTitle(campusinfoProblem.getTitle());
			dao.insert(campusinfoProblem);
			campusinfoProDetailDao.insert(campusinfoProDetail);
		}else{
			campusinfoProblem.preUpdate();
			dao.update(campusinfoProblem);
		}
	}

	
	@Transactional(readOnly = false)
	public void delete(CampusinfoProblem campusinfoProblem) {
		super.delete(campusinfoProblem);
	}
	
}